#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 25 17:10:14 2011

@author: camsparr
"""

from os import getenv, system, listdir, chdir

home = getenv('HOME')

# will add support for custom install directories later. (11/2/2011).
#temp = raw_input('Where would you like to install mpy3? \n \
     #hit return for default (' + home + ') : ')
#if not temp == '':
    #home = temp
musicdir = raw_input('Please specify where you would like your feeds to download to: \n \
    hit return for default (' + home + '/Music/) : ')
    
if musicdir == '':
	musicdir = home + '/Music/'
		
system('mkdir ' + musicdir)
	
defaultfeed = raw_input('Would you like to install the default feeds? \n \
     (radiolab, pitchfork best new tracks, KEXP song of\n \
     the day, and gorilla vs bear) Y/n: ')
   
indir = home + '/.mpy3/lib/'

print('** INSTALLING BEAUTIFUL SOUP **')
chdir('BeautifulSoup-3.2.0')
system('sudo python setup.py install')
chdir('..')

print('** CREATING EXECUTABLE **')
system('chmod +x mpy3.py')

print('** CREATING SUPPORT DIRECTORIES **')
if not listdir(home).__contains__('.mpy3'):
    system('mkdir ' + home + '/.mpy3')
if not listdir(home + '/.mpy3').__contains__('lib'):
    system('mkdir ' + home + '/.mpy3/lib')

print('** FINISHING COPYING DATA **')
system('sudo cp mpy3.py /usr/bin/mpy3')
system('cp lib/mpy3funcs.py ' + indir + 'mpy3funcs.py')

exstng_lib = listdir(indir)
install_lib = listdir('lib/')
if not defaultfeed.lower() == 'n':
	
	# create default download directories:
	if not listdir(musicdir).__contains__('pitchfork_bestnew'):
		system('mkdir ' + musicdir + '/pitchfork_bestnew')
	if not listdir(musicdir).__contains__('gorilla_vs_bear'):
		system('mkdir ' + musicdir + '/gorilla_vs_bear')
	if not listdir(musicdir).__contains__('kexp_songoftheday'):
		system('mkdir ' + musicdir + '/kexp_songoftheday')
	if not listdir(musicdir).__contains__('radiolab'):
		system('mkdir ' + musicdir + '/radiolab')

	for f in install_lib:
		#if not exstng_lib.__contains__(f):
		system('cp lib/' + f + ' ' + indir + f)
